﻿using System;
using System.Configuration;

/// <summary>
/// Summary description for Class1
/// </summary>
/// 


namespace Bestlife.ERP.DataAccess
{ 
   

    public class calculations 
    {
            Boolean upd = false;
            int Num_agents = 0;
            int Num_diamond=0;
            int Num_Ruby = 0;
            int Num_SED = 0;
            int Num_SD = 0;

            //from shopping cart;   id + pv + t sales+ bv +tpv  (26 th day of month ppv = 0 )
            Double product_bv;
            Double product_pv;
            Double product_tpv;
            Double product_sales;
            Double cpv;

            public void calculationss(String user_id, Double p_bv, Double ppv, Double psales)

           // public calculations()

            {

                DataAccess.users usr = new DataAccess.users();
                cpv = usr.users_cpv(user_id);

         
            
#region Starter kit

            if (ppv < 25) // 5% presenter
            {

                //Bestlife.ERP.BusinessRules._5presnter();


            }


            // }   // 5% presenter   

            #endregion  

#region 5% presenter

            if (ppv>=25 && cpv>=50 && cpv<100) // 5% presenter
                
            {                       
                
                                    //

                                    try
                                    {
                                        String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                                        Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                                        String updStatus = "UPDATE Bonus  SET user_Status='2',bv='" + 0.0 + "',ppv='"+0.0+"' WHERE User_id='" + user_id + "'";
                                        upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                                    }


                                    catch 
                                    {

                                    }


                                    finally
                                    {
                                        clsCon.conn_new.Close();
                    
                                    }








           }

           // }   // 5% presenter   

#endregion  

#region 10% presenter

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                String updStatus = "UPDATE Bonus  SET user_Status='3',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
            }


            catch
            {

            }


            finally
            {
                clsCon.conn_new.Close();

            }


            

            #endregion  

#region 15% presenter

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                String updStatus = "UPDATE Bonus  SET user_Status='4',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
            }


            catch
            {

            }


            finally
            {
                clsCon.conn_new.Close();

            }


            // }   // 15% presenter   

            #endregion  
 
#region Agent


            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                String updStatus = "UPDATE Bonus  SET user_Status='5',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
            }


            catch
            {

            }


            finally
            {
                clsCon.conn_new.Close();

            }



           

            #endregion       

#region Ruby

           

           if ((ppv >= 25 && cpv >= 200 && cpv< 300) ||(Num_agents>3 && cpv >= 1500 && ppv > 25) || (Num_agents >= 2 && cpv >= 3200 && ppv >= 25))   // Agent
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    String updStatus = "UPDATE Bonus  SET user_Status='6',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }


            }


 #endregion  

#region Diamond


           


            if((ppv>= 4800) || (Num_Ruby>2 && cpv>=6000) || (Num_Ruby>3 && cpv>=6000)) // Diamond
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    String updStatus = "UPDATE Bonus  SET user_Status='7',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }

            }


            // }   // diamond  

            #endregion  

#region Senior Diamond

           



            if ((ppv >= 20000) || (Num_diamond>=1 && Num_Ruby>=6 && cpv>=25000) || (Num_diamond>=2 && Num_Ruby>=4 && cpv>=25000)||(Num_diamond>2 && cpv>=50000) || (Num_diamond>=3 && cpv>=25000))   // S diamond
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    String updStatus = "UPDATE Bonus  SET user_Status='8',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }

            }


           

            #endregion  

#region Senior Executive Diamond





            if ((ppv >= 80000) || (Num_diamond >= 1 && Num_Ruby >= 6 && cpv >= 25000) || (Num_diamond >= 2 && Num_Ruby >= 4 && cpv >= 25000) || (Num_diamond > 2 && cpv >= 50000) || (Num_diamond >= 3 && cpv >= 25000))   // S diamond
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    String updStatus = "UPDATE Bonus  SET user_Status='9',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }

            }




            #endregion  

#region Crown Diamond

                
            if ((ppv >= 32000) || (Num_SED >= 3 && cpv >= 400000) || (Num_SED >= 2 && cpv >= 800000) ||(Num_SD >= 4 && Num_SED>=2 && cpv >= 400000)||(Num_SED>=1 && Num_SD>=6 && cpv>=400000))   // S diamond
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    String updStatus = "UPDATE Bonus  SET user_Status='10',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }

            }




            #endregion  


//#region 2Crown Diamond


//            if ((ppv >= 32000) || (Num_SED >= 3 && cpv >= 400000) || (Num_SED >= 2 && cpv >= 800000) || (Num_SD >= 4 && Num_SED >= 2 && cpv >= 400000) || (Num_SED >= 1 && Num_SD >= 6 && cpv >= 400000))   // S diamond
//            {

//                try
//                {
//                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
//                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
//                    String updStatus = "UPDATE Bonus  SET user_Status='11',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
//                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
//                }


//                catch
//                {

//                }


//                finally
//                {
//                    clsCon.conn_new.Close();

//                }

//            }




//            #endregion  


//#region 3Crown Diamond


//            if ((ppv >= 32000) || (Num_SED >= 3 && cpv >= 400000) || (Num_SED >= 2 && cpv >= 800000) || (Num_SD >= 4 && Num_SED >= 2 && cpv >= 400000) || (Num_SED >= 1 && Num_SD >= 6 && cpv >= 400000))   // S diamond
//            {

//                try
//                {
//                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
//                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
//                    String updStatus = "UPDATE Bonus  SET user_Status='12',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
//                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
//                }


//                catch
//                {

//                }


//                finally
//                {
//                    clsCon.conn_new.Close();

//                }

//            }




//            #endregion  


//#region 4Crown Diamond


//            if ((ppv >= 32000) || (Num_SED >= 3 && cpv >= 400000) || (Num_SED >= 2 && cpv >= 800000) || (Num_SD >= 4 && Num_SED >= 2 && cpv >= 400000) || (Num_SED >= 1 && Num_SD >= 6 && cpv >= 400000))   // S diamond
//            {

//                try
//                {
//                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
//                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
//                    String updStatus = "UPDATE Bonus  SET user_Status='13',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
//                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
//                }


//                catch
//                {

//                }


//                finally
//                {
//                    clsCon.conn_new.Close();

//                }

//            }




//            #endregion  


//#region 5Crown Diamond


//            if ((ppv >= 32000) || (Num_SED >= 3 && cpv >= 400000) || (Num_SED >= 2 && cpv >= 800000) || (Num_SD >= 4 && Num_SED >= 2 && cpv >= 400000) || (Num_SED >= 1 && Num_SD >= 6 && cpv >= 400000))   // S diamond
//            {

//                try
//                {
//                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
//                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
//                    String updStatus = "UPDATE Bonus  SET user_Status='14',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + user_id + "'";
//                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
//                }


//                catch
//                {

//                }


//                finally
//                {
//                    clsCon.conn_new.Close();

//                }

//            }




//            #endregion  


        } // Public Calculations
    } //Public class calculations

}//public namespace